package com.catsic.base.specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;

/**
 * ClassName: QueryWraper
 * Description: 包装用于构建JPA动态查询时所需的对象
 * date: 2014年4月28日 下午2:00:43
 * author: yangyd
 */
public class QueryWraper<T> {

	/**
     * @param root JPA Root
     * @param cb JPA CriteriaBuilder
     * @param predicates JPA Predicate 集合
     * @param orders
     */
	public QueryWraper(Root<T> root, CriteriaBuilder cb, List<Predicate> predicates, List<Order> orders){
		this.root = root;
		this.cb = cb;
		this.predicates = predicates;
        this.orders = orders;
	}
	
	/**
	 * JPA Root
	 */
	private Root<T> root; 
	/**
	 * JPA CriteriaBuilder
	 */
	private CriteriaBuilder cb;
	/**
	 * JPA Predicate 集合
	 */
	private List<Predicate> predicates;
    /**
     * JPA Order集合
     */
    private List<Order> orders;
	/**
	 * @return the root
	 */
	public Root<T> getRoot() {
		return root;
	}
	/**
	 * @param root the root to set
	 */
	public void setRoot(Root<T> root) {
		this.root = root;
	}
	/**
	 * @return the cb
	 */
	public CriteriaBuilder getCb() {
		return cb;
	}
	/**
	 * @param cb the cb to set
	 */
	public void setCb(CriteriaBuilder cb) {
		this.cb = cb;
	}
	/**
	 * @return the predicates
	 */
	public List<Predicate> getPredicates() {
		return predicates;
	}
	/**
	 * @param predicates the predicates to set
	 */
	public void setPredicates(List<Predicate> predicates) {
		this.predicates = predicates;
	}
	
	public void addPredicate(Predicate predicate){
		this.predicates.add(predicate);
	}

    public List<Order> getOrders() {
        return orders;
    }

    public void setOrders(List<Order> orders) {
        this.orders = orders;
    }

    public void addOrder(Order order){
        this.orders.add(order);
    }
}
